const app = getApp()
const api = require('../../../../config/api.js')
Page({
  data: {
    words:"",
    wordslength:15
  },
  onLoad() {
    this.setData({
      words: app.globalData.xuserInfo.words ? app.globalData.xuserInfo.words : app.globalData.userInfo.words
    })
  },
  onUnload:function(){
    qq.navigateTo({
      url: "/pages/mine/profile/profile"
    })
  },

  getvalue:function(e){
    console.log(e.detail.value)
    wordslength=15-e.detail.value.length
    this.setData({
      words: e.detail.value,
      wordslength:wordslength
    })
  },
  finish:function(e){
    words = this.data.words
    this.sendwords(words)
    
    qq.navigateTo({
      url: '/pages/mine/profile/profile'　　
    })
  },
  sendwords:function(words){
    app.globalData.xuserInfo.words = words
    qq.request({
      url: api.UploadXUserInfo,
      data: {"xuserInfo":{"words":words}},
      header: {
        'Content-Type': 'application/json',
        'Xworld-Token': app.globalData.token
      },
      method: 'POST',
      success: res => {
        console.log('res success qq.UploadXUserInfo', res)

      },  
      fail: res => {
        console.log('res fail', res)
      }
    })
  },
  backtoprepage:function(e){
    qq.navigateTo({
      url: '/pages/mine/profile/profile'　　
    })
  }
})

